<template>
	<div class="app-container">
	  <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="120px">
		<el-form-item label="模型名称" prop="modelName">
		  <el-input
			v-model="queryParams.modelName"
			placeholder="请输入模型名称"
			clearable
			@keyup.enter="handleQuery"
		  />
		</el-form-item>
		<el-form-item label="省" prop="province">
		  <el-select v-model="queryParams.province" placeholder="请选择省" @change="chooseProvince" clearable>
			 <el-option
				  v-for="item in provinceData"
				  :key="item.id"
				  :label="item.name"
				  :value="item.id">
			  </el-option>
		  </el-select>
		</el-form-item>
		<el-form-item label="市" prop="city">
		  <el-select v-model="queryParams.city" placeholder="请选择市" @change="chooseCity" clearable>
			 <el-option
				  v-for="item in cityData"
				  :key="item.id"
				  :label="item.name"
				  :value="item.id">
			  </el-option>
		  </el-select>
		</el-form-item>
		<!--<el-form-item label="区/县" prop="areaId">
		  <el-select v-model="queryParams.areaId" placeholder="请选择区/县" clearable>
			 <el-option
				  v-for="item in areaData"
				  :key="item.id"
				  :label="item.name"
				  :value="item.id">
			  </el-option>
		  </el-select>
		</el-form-item>-->
		<el-form-item>
		  <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
		  <el-button plain icon="Refresh" @click="resetQuery">重置</el-button>
		</el-form-item>
	  </el-form>
  
	  <el-row :gutter="10" class="mb8">
		<!--<el-col :span="1.5">
		  <el-button
			type="primary"
			plain
			icon="Plus"
			@click="handleAdd"
		  >新增</el-button>
		</el-col>-->
		<!--<el-col :span="1.5">
		  <el-button
			type="success"
			plain
			icon="Edit"
			:disabled="single"
			@click="handleUpdate"
			v-hasPermi="['system:difference:edit']"
		  >修改</el-button>
		</el-col>-->
		<!--<el-col :span="1.5">
		  <el-button
			type="danger"
			plain
			icon="Delete"
			:disabled="multiple"
			@click="handleDelete"
			v-hasPermi="['system:difference:remove']"
		  >删除</el-button>
		</el-col>-->
		<!--<el-col :span="1.5">
		  <el-button
			type="warning"
			plain
			icon="Download"
			@click="handleExport"
			v-hasPermi="['system:difference:export']"
		  >导出</el-button>
		</el-col>-->
		<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
	  </el-row>
  
	  <el-table v-loading="loading" :data="casualtiesList" stripe>
		<!--<el-table-column type="selection" width="55" align="center" />-->
		<el-table-column label="模型名称" align="center" prop="modelName" >
			<template #default="scope">
			  <el-button type="text" @click="edit(scope.row)">{{
				scope.row.modelName
			  }}</el-button>
			</template>
		  </el-table-column>
		<el-table-column label="省" align="center" prop="province" />
		<el-table-column label="市" align="center" prop="city" />
		
		
		<el-table-column label="是否默认" align="center" prop="isDefault">
			<template #default="scope">
			<span v-if="scope.row.isDefault=='0'">否</span>
			<span v-if="scope.row.isDefault=='1'">是</span>
		  </template>
		</el-table-column>
		<el-table-column label="维护人" align="center" prop="createUserName" />
		<el-table-column label="维护人所属单位" align="center" prop="orgName" />
		
		<!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
		  <template #default="scope">
			<el-button
			  type="text"
			  @click="handleDelete(scope.row)"
						  v-if="scope.row.taskStatus!=2 && scope.row.flag==2"
			>删除</el-button>
		  </template>
		</el-table-column>-->
	  </el-table>
	  
	  <pagination
		v-show="total>0"
		:total="total"
		v-model:page="queryParams.page"
		v-model:limit="queryParams.rows"
		@pagination="getList"
	  />
  
	  <!-- 添加或修改区县致死性差异性对话框 -->
	  <el-dialog :title="title" v-model="open" width="900px" append-to-body>
		<el-form ref="rescueforceRef" :model="form" :rules="rules" label-width="120px">
			<p class="dialogTitle">{{title}}</p>
				   <el-row>
					 <el-col :span="12">
					 <el-form-item label="模型名称" prop="modelName" v-if="isCopy">
						 {{form.modelName}}		          
				  </el-form-item>
				  <el-form-item label="模型名称" prop="modelName" v-else>
						 <el-input v-model="form.modelName" placeholder="请输入模型名称" />		          
				  </el-form-item>
				 </el-col>
				 <el-col :span="12">
					 <el-form-item label="是否默认" prop="" v-if="isCopy">
						 {{form.isDefault=='0'?'否':'是'}}		          
				  </el-form-item>
				  <el-form-item label="是否默认" prop="" v-else>
						 <el-select v-model="form.isDefault" disabled style="width: 100%;">
					 <el-option
					  v-for="item in [
						{ value: '0', label: '否' },
						{ value: '1', label: '是' },
					  ]"
					  :key="item.value"
					  :label="item.label"
					  :value="item.value"
					>
					</el-option>
					 </el-select>	          
				  </el-form-item>
				 </el-col>
				 
				 </el-row>
				   <el-row>
					<el-col :span="24">
				  <el-form-item label="地区" prop="" v-if="isCopy||isEditDefault">
					{{form.province}} - {{form.city}}
				  </el-form-item>
				  <el-form-item label="地区" prop="" v-else>
					
					<el-form-item label="省" prop="provinceId" label-width="50px">
						<el-select v-model="form.provinceId" :disabled="isDisableds" placeholder="请输入省" @change="chooseFormProvince"  style="width: 160px;">
							 <el-option
						  v-for="item in provinceFormData"
						  :key="item.id"
						  :label="item.name"
						  :value="item.id">
						  </el-option>
						  </el-select>
					  </el-form-item>
					  <el-col :span="16">
						  <el-form-item label="市" prop="" label-width="50px">
							  <el-radio-group v-model="radio" @change="chooseRadio">
									<el-radio label="1">全部</el-radio>
									<el-radio label="2">
										<el-select v-model="form.cityId" placeholder="请输入市" multiple collapse-tags :disabled="isCityEdit" style="width: 200px;">
										 <el-option
									  v-for="item in cityFormData"
									  :key="item.id"
									  :label="item.name"
									  :value="item.id">
									  </el-option>
									  </el-select>
									</el-radio>
								  </el-radio-group>
								</el-form-item>
							</el-col>
					  
						
  
				  </el-form-item>
				  </el-col>
			 
			 </el-row>
				 <el-row>
					 <el-col :span="12">
					 <el-form-item label="维护人" prop="">
						 {{form.createUserName}}		          
				  </el-form-item>
				 </el-col>
				 <el-col :span="12">
					 <el-form-item label="维护人单位" prop="">
						 {{form.orgName}}		          
				  </el-form-item>
				 </el-col>
				 
				 </el-row>
				 
				   
		  <el-row>
					  <el-col :span="6" class="tab-title">
						  救援队伍需求模型
					  </el-col>
				  </el-row>			
				  <el-row style="margin: 20px 0;font-size: 15px;">
					  <el-col :span="22" :offset="2">
						  救援队伍包括专业救援力量、民间救援力量和社会其他力量。救援队伍与震级、灾区人数有关。模型公式：
					  </el-col>
				  </el-row>
				  <el-row>
					  <el-col :span="18" :offset="4" v-if="isCopy">
						  <span style="font-size: 16px;">
							  
							  1、M＜5：以当地驻军和武警消防为主，基本无需外地救援队伍。<br/><br/>
							  2、5 ≤ M＜6：R<sub>r</sub> = R * 0.009(0.8% ~ 1%)<br/><br/>
							  3、6 ≤ M＜7：R<sub>r</sub> = R * 0.008(0.5% ~ 1%)<br/><br/>
							  4、M ≥ 7：R<sub>r</sub> = R * 0.04(3% ~ 5%)<br/><br/>
							  5、无论震级多大，所需救援队伍人数上限值为20万人。<br/><br/>
							  参数说明：M--地震震级；R<sub>r</sub>--救援需求人数（人）；R--受灾人数（人）<br/><br/>
							  6、其中专业救援力量占70%、民间救援力量20%、社会其他力量10%。<br/><br/>
						  </span>
						  
					  </el-col>
					  <el-col :span="20" :offset="4" v-else>
						  <span style="font-size: 16px;">
							  
							  1、M＜5：以当地驻军和武警消防为主，基本无需外地救援队伍。<br/><br/><br/>
							  2、5 ≤ M＜6：R<sub>r</sub> = R * 
							  <el-form-item prop="rescueRanksModelNumber1" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.rescueRanksModelNumber1" placeholder="" style="width: 80px;" />
							  </el-form-item>
							  (0.8% ~ 1%)<br/><br/>
							  3、6 ≤ M＜7：R<sub>r</sub> = R * 
							  <el-form-item prop="rescueRanksModelNumber2" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.rescueRanksModelNumber2" placeholder="" style="width: 80px;" />
							  </el-form-item>	
							  (0.5% ~ 1%)<br/><br/>
							  4、M ≥ 7：R<sub>r</sub> = R * 
							  <el-form-item prop="rescueRanksModelNumber3" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.rescueRanksModelNumber3" placeholder="" style="width: 80px;" />
							  </el-form-item>
							  (3% ~ 5%)<br/><br/>
							  5、无论震级多大，所需救援队伍人数上限值为20万人。<br/>
							  参数说明：M--地震震级；R<sub>r</sub>--救援需求人数（人）；R--受灾人数（人）<br/>
							  6、其中专业救援力量占
							  <el-form-item prop="majorRescueForceProportion" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.majorRescueForceProportion" placeholder="" style="width: 80px;" />
							  </el-form-item>	
								  %、民间救援力量
							  <el-form-item prop="popularRescueForceProportion" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.popularRescueForceProportion" placeholder="" style="width: 80px;" />
							  </el-form-item>
								  %、社会其他力量
							  <el-form-item prop="societyOtherForceProportion" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.societyOtherForceProportion" placeholder="" style="width: 80px;" />
							  </el-form-item>
								  %。<br/>
						  </span>
						  
					  </el-col>
				  </el-row>
		  
		  <el-row>
					  <el-col :span="6" class="tab-title">
						  医务人员需求模型
					  </el-col>
				  </el-row>			
	  
				  <el-row>
					  <el-col :span="16" :offset="4" v-if="isCopy">
						  <span style="font-size: 16px;">
							  医务人员分为医生、护士、心理医生。<br/>
							  医务人员需求与救援人员需求成一定比例：<br/><br/>
							  Yd = R<sub>r</sub> * 0.06 (0.05 ~ 0.1)<br/><br/>
							  
							  参数说明：  Yd--医务人员需求（人）；    R<sub>r</sub>--救援需求人数（人）<br/>
							  其中医生占30%、护士占65%、心理医生占5%。<br/>
							  
						  </span>
						  
					  </el-col>
					  <el-col :span="16" :offset="4" v-else>
						  <span style="font-size: 16px;">
							  医务人员分为医生、护士、心里医生。<br/>
							  医务人员需求与救援人员需求成一定比例：<br/><br/>
							  Yd = R<sub>r</sub> * 
							  <el-form-item prop="medicalStaffModelNumber" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.medicalStaffModelNumber" placeholder="" style="width: 80px;" />
							  </el-form-item>
								   (0.05 ~ 0.1)<br/><br/>
							  
							  参数说明：  Yd--医务人员需求（人）；    R<sub>r</sub>--救援需求人数（人）<br/>
							  其中医生占
							  <el-form-item prop="doctorProportion" label-width="0px" style="display: inline-block;">
								  <el-input v-model="form.doctorProportion" placeholder="" style="width: 80px;" />
							  </el-form-item>
							   %、护士占
							  <el-form-item prop="nurseProportion" label-width="0px" style="display: inline-block;">
								   <el-input v-model="form.nurseProportion" placeholder="" style="width: 80px;" />
							  </el-form-item>
								%、心理医生占
							  <el-form-item prop="psychologistProportion" label-width="0px" style="display: inline-block;">
								<el-input v-model="form.psychologistProportion" placeholder="" style="width: 80px;" /> 
							  </el-form-item>
								%。<br/>
							  
						  </span>
						  
					  </el-col>
				  </el-row>
		</el-form>
		<template #footer>
		  <div class="dialog-footer">
			<el-button type="primary" @click="copyForm" v-if="isCopy">复 制</el-button>
			<el-button type="primary" @click="saveForm" v-if="!isCopy&&Default=='1'" :disabled="isDisabled">保 存</el-button>
			<el-button type="primary" @click="editForm" v-if="!isCopy&&Default=='0'" :disabled="isDisabled">保 存</el-button>
			<el-button type="primary" @click="delForm" v-if="!isCopy&&Default=='0'">删 除</el-button>
			<el-button plain @click="cancel">取 消</el-button>
		  </div>
		</template>
	  </el-dialog>
	</div>
  </template>
  
  <script setup>
  import { listRescueforce, getModelRescueforce, getModelRescueforceForCopy, delRescueforce, addRescueforce, updateRescueforce } from "@/api/modelmanage/rescueforce";
  import { getProvince, getProvince2, getChildArea} from "@/api/system/division";
  import { getLanderRoles, getLanderProvince } from "@/api/basedatamanage/common.js"
  import { getUserId, setUserId } from '@/utils/auth'
  import { isDecimal } from '@/utils/validate'
  import useUserStore from '@/store/modules/user'
  
  const userStore = useUserStore();
  const { proxy } = getCurrentInstance();
  
  const casualtiesList = ref([]);
  const isEdit = ref(false);
  const isCopy = ref(true);
  const Default = ref("1");
  const radio = ref("1");
  const isCityEdit = ref(true);
  const isEditDefault = ref(true);
  const isShow = ref(true);
  const open = ref(false);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const title = ref("");
  const submitTime = ref("");//提交时间
  const provinceData = ref([]);//省
  const cityData = ref([]);//市
  const areaData = ref([]);//区、县
  
  const provinceFormData = ref([]);//表单省 
  const cityFormData = ref([]);//表单市
  const areaFormData = ref([]);//表单区、县
  const isDisabled = ref(false);
  
  const validatorFactror = (rule, value, callback) => {
	  // if (!Number(value)) {
	  //   return callback(new Error('只能输入数字'))
	  // }
	  const reg = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g
	  if(!reg.test(value)){
		  callback(new Error('只能输入数字'))
	  }else{
		  if(rule.field=='rescueRanksModelNumber1'){
			  if(0.8>value*100||value*100>1){
				  callback(new Error('不在区间内！'))
			  }else{
				  callback()
			  }
		  }else if(rule.field=='rescueRanksModelNumber2'){
			  if(0.5>value*100||value*100>1){
				  callback(new Error('不在区间内！'))
			  }else{
				  callback()
			  }
		  }else if(rule.field=='rescueRanksModelNumber3'){
			  if(3>value*100||value*100>5){
				  callback(new Error('不在区间内！'))
			  }else{
				  callback()
			  }
		  }else if(rule.field=='medicalStaffModelNumber'){
			  if(0.05>value||value>0.1){
				  callback(new Error('不在区间内！'))
			  }else{
				  callback()
			  }
		  }else if(rule.field=='majorRescueForceProportion'||rule.field=='popularRescueForceProportion'||rule.field=='societyOtherForceProportion'){
			  const majorRescueForceProportionValue = form.value.majorRescueForceProportion?Number(form.value.majorRescueForceProportion):0;
			  const popularRescueForceProportionValue = form.value.popularRescueForceProportion?Number(form.value.popularRescueForceProportion):0;
			  const societyOtherForceProportionValue = form.value.societyOtherForceProportion?Number(form.value.societyOtherForceProportion):0;
			  if(majorRescueForceProportionValue+popularRescueForceProportionValue+societyOtherForceProportionValue==100){
				  proxy.$refs['rescueforceRef'].clearValidate('majorRescueForceProportion');
				  proxy.$refs['rescueforceRef'].clearValidate('popularRescueForceProportion');
				  proxy.$refs['rescueforceRef'].clearValidate('societyOtherForceProportion');
				  callback()
			  }else{
				  callback(new Error('占比和不为100%!'))
			  }
		  }else if(rule.field=='doctorProportion'||rule.field=='nurseProportion'||rule.field=='psychologistProportion'){
			  const doctorProportionValue = form.value.doctorProportion?Number(form.value.doctorProportion):0;
			  const nurseProportionValue = form.value.nurseProportion?Number(form.value.nurseProportion):0;
			  const psychologistProportionValue = form.value.psychologistProportion?Number(form.value.psychologistProportion):0;
			  if(doctorProportionValue+nurseProportionValue+psychologistProportionValue==100){
				  proxy.$refs['rescueforceRef'].clearValidate('doctorProportion');
				  proxy.$refs['rescueforceRef'].clearValidate('nurseProportion');
				  proxy.$refs['rescueforceRef'].clearValidate('psychologistProportion');
				  callback()
			  }else{
				  callback(new Error('占比和不为100%!'))
			  }
		  }
	  }
  }
  
  const data = reactive({
	form: {},
	queryParams: {
	  page: 1,
	  rows: 10,
	  province: null,
	  city: null,
	  
	},
	rules: {
	  taskCode: [
		{ required: true, message: "任务编号不能为空", trigger: "blur" }
	  ],
	  modelName: [
		{ required: true, message: "模型名称不能为空", trigger: "blur" }
	  ],
	  province: [
		{ required: true, message: "省不能为空", trigger: "blur" }
	  ],
	  provinceId: [
		{ required: true, message: "省不能为空", trigger: "change" }
	  ],
	  city: [
		{ required: true, message: "市不能为空", trigger: "blur" }
	  ],
	  cityId: [
		{ required: true, message: "市不能为空", trigger: "blur" }
	  ],
	  area: [
		{ required: true, message: "区/县不能为空", trigger: "blur" }
	  ],
	  areaId: [
		{ required: true, message: "区/县 不能为空", trigger: "blur" }
	  ],
	  rescueRanksModelNumber1: [{ required: true, message: "请输入数字", trigger: "blur" },{ validator:validatorFactror,trigger: "blur"}],
	  rescueRanksModelNumber2: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  rescueRanksModelNumber3: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  majorRescueForceProportion: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  popularRescueForceProportion: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  societyOtherForceProportion: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  medicalStaffModelNumber: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  doctorProportion: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  nurseProportion: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	  psychologistProportion: [{ required: true, message: "请输入数字", trigger: "blur" },{validator:validatorFactror,trigger: "blur"}],
	}
  });
  
  const { queryParams, form, rules } = toRefs(data);
  
  /** 查询人口伤亡计算模型列表 */
  function getList() {
	loading.value = true;
	listRescueforce(queryParams.value).then(response => {
	  casualtiesList.value = response.data.rows?response.data.rows:[];
	  total.value = response.data.total;
	  loading.value = false;
	});
  }
  
  /** 获取省列表 */
  function getProvinceData() {
	  getProvince2().then(response => {
		  provinceData.value = response.data;
	  });
  }
  
  function getProvinceFormData() {
	  getProvince().then(response => {
		  provinceFormData.value = response.data;
	  });
  }
  
  function editProvinceFormData(provinceId,cityId) {
	  getProvince().then(response => {
		  provinceFormData.value = response.data;
	  });
	  getChildArea(provinceId).then(response => {
	  cityFormData.value = response.data;
	  });
	  getChildArea(cityId).then(response => {
		  areaFormData.value = response.data;
	  });
  }
  
  function chooseRadio(value){
	  console.log(value)
	  if(value == "2"){
		  isCityEdit.value = false
		  
	  }else{
		  isCityEdit.value = true
		  form.value.city = "全部"
		  form.value.cityId = ""
	  }
  }
  
  function chooseProvince(value){
	  queryParams.value.city = null;
	  queryParams.value.area = null;
	  cityData.value = [];
	  areaData.value = [];
	  getChildArea(value).then(response => {
	  cityData.value = response.data;
	  });
  //	provinceData.value.map(item => {//遍历数据
  //		if(item.id == value){
  //			if(item.name == "北京市"||item.name == "天津市"||item.name == "上海市"||item.name == "重庆市"){
  //		    cityData.value.push(JSON.parse(JSON.stringify(item)));
  //			}else{
  //				getChildArea(value).then(response => {
  //			    cityData.value = response.data;
  //				});
  //			}
  //			return;
  //		}   
  //})		
  }
  
  function chooseFormProvince(value){
	  form.value.city = null;
	  form.value.area = null;
	  cityFormData.value = [];
	  areaFormData.value = [];
	  getChildArea(value).then(response => {
	  cityFormData.value = response.data;
	  });	
  }
  
  function chooseCity(value){
	  queryParams.value.areaId = null;
	  areaData.value = [];
	  getChildArea(value).then(response => {
		  areaData.value = response.data;
	  });
  }
  
  function chooseFormCity(value){
	  form.value.area = null;
	  areaFormData.value = [];
	  getChildArea(value).then(response => {
		  areaFormData.value = response.data;
	  });
  }
  function chooseTaskName(value){
	  taskNameData.value.map(item => {//遍历数据
		  if(item.taskName == value){
			  form.value.taskCode = item.taskNum;
			  console.log(form.value.taskCode)
			  return;
		  }   
	  })	
  
  }
  // 取消按钮
  function cancel() {
	open.value = false;
	reset();
  }
  
  // 表单重置
  function reset() {
	form.value = {
	  id: null,
	  modelName: null,
	  province: null,
	  provinceId: null,
	  city: null,
	  cityId: null,
	  area: null,
	  areaId: null,
  
	  isDefault: null,
  
  
	};
	proxy.resetForm("rescueforceRef");
  }
  
  /** 搜索按钮操作 */
  function handleQuery() {
	queryParams.value.page = 1;
	
	getList();
  }
  
  /** 重置按钮操作 */
  function resetQuery() {
	  cityData.value = [];
	  areaData.value = [];
	proxy.resetForm("queryRef");
	handleQuery();
  }
  
  // 多选框选中数据
  function handleSelectionChange(selection) {
	ids.value = selection.map(item => item.id);
	single.value = selection.length != 1;
	multiple.value = !selection.length;
  }
  
  //获取当前日期函数
  function getNowFormatDate() {
	let date = new Date(),
	  seperator1 = '-', //格式分隔符
	  year = date.getFullYear(), //获取完整的年份(4位)
	  month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
	  strDate = date.getDate() // 获取当前日(1-31)
	if (month >= 1 && month <= 9) month = '0' + month // 如果月份是个位数，在前面补0
	if (strDate >= 0 && strDate <= 9) strDate = '0' + strDate // 如果日是个位数，在前面补0
   
	let currentdate = year + seperator1 + month + seperator1 + strDate 
	return currentdate
  }
  
  
  
  /** 查看按钮操作 */
  function edit(row) {
	reset();
	const id = row.id 
	if(row.isDefault=="1"){
		isCopy.value = true;
		Default.value = "1";
		title.value = "系统默认救援力量需求评估模型";
	}else{
		isCopy.value = false;
		Default.value = "0";
		title.value = "救援力量需求评估模型";
	}
	
	getModelRescueforce(id).then(response => {
		
	  form.value = response.data;
	  
	  open.value = true;
	  if(form.value.city=="全部"){
		  radio.value = "1"
		  isCityEdit.value = true
	  }else{
		  radio.value = "2"
		  isCityEdit.value = false
	  }
	  if(form.value.isDefault=="0"){
		  isEditDefault.value = true
	  }else{
		  isEditDefault.value = false
	  }
	  
	});
  }
  
  /*复制*/
  const copyForm = async()=> {
	  await getModelRescueforceForCopy(form.value.id).then(response => {  	
	  form.value = response.data;
	  isCopy.value = false;
		  form.value.modelName = null;
		  form.value.isDefault = "0";  
	});
	  
	  title.value = "复制救援力量需求评估模型";
	  if(isDisableds.value){
		  form.value.provinceId = AdminProvinceId.value;
		  chooseFormProvince(form.value.provinceId);
		}
  }
  
  /*新增*/
  function saveForm() {
	  console.log("新增")
	  
	  proxy.$refs["rescueforceRef"].validate(valid => {
	  if (valid) {
		  console.log("111")
		  if(radio.value == "1"){
				  form.value.city = "全部"
			  }else{
				  if(form.value.cityId!=null){
					  console.log(form.value.cityId)
					  form.value.city = JSON.parse(JSON.stringify(form.value.cityId)).join(",")
				  }				 
			  }
			  console.log("333")
			  isDisabled.value = true;
			  addRescueforce({
				  "modelName":form.value.modelName,
			  "rescueRanksModelNumber1":form.value.rescueRanksModelNumber1,
			  "rescueRanksModelNumber2":form.value.rescueRanksModelNumber2,
			  "rescueRanksModelNumber3":form.value.rescueRanksModelNumber3,
			  "majorRescueForceProportion":form.value.majorRescueForceProportion,    
			  "popularRescueForceProportion":form.value.popularRescueForceProportion,
			  "societyOtherForceProportion":form.value.societyOtherForceProportion,
			  "medicalStaffModelNumber":form.value.medicalStaffModelNumber,
			  "doctorProportion":form.value.doctorProportion,
			  "nurseProportion":form.value.nurseProportion,    
			  "shortSymbol":form.value.shortSymbol,
			  "psychologistProportion":form.value.psychologistProportion,
			  "isDefault":form.value.isDefault,
			  "province":form.value.provinceId,
			  "city":form.value.city,
			  }).then(response => {
				  if(response.message=="保存成功!"){
					  proxy.$modal.msgSuccess("新增成功");
					  open.value = false;
					  isDisabled.value = false;
					  getList();
				  }else{
					  proxy.$modal.msgError(response.message);
				  }
				
				
				
			  }).catch(err=>{isDisabled.value = false;});
		  }
	})
	  
  }
  /*编辑*/
  function editForm() {
	  console.log("编辑")
	  proxy.$refs["rescueforceRef"].validate(valid => {
	  if (valid) {
			  isDisabled.value = true;
			  updateRescueforce(form.value).then(response => {
				  if(response.message=="修改失败，只能修改自己创建的模型"){
					  isDisabled.value = false;
					  proxy.$modal.msgWarning(response.message);
				  }else{
					  proxy.$modal.msgSuccess(response.message);
					  open.value = false;
					  isDisabled.value = false;
					getList();
				  }
				//proxy.$modal.msgSuccess("修改成功");
				
			  }).catch(err=>{isDisabled.value = false;});
		  }
	})
	  
  }
  /*删除*/
  function delForm() {
	  console.log("删除")
	  
	  const id = form.value.id;
	proxy.$modal.confirm('是否确认删除？').then(function() {
	  
	}).then(() => {
		delRescueforce(id).then(response => {
		  console.log(response.message)
		  if(response.message=="删除失败，只能删除自己创建的模型"){    		
			  proxy.$modal.msgWarning(response.message);
		  }else{
			  proxy.$modal.msgSuccess(response.message);    		
				getList();
				open.value = false;
		  }
			 
	  });
	}).catch(() => {});
	  
  }
  
  // 权限
  const isAdmin = async () => {
	  let res = await getLanderRoles()
	  const { code, data } = res
	  if (code == 200) {
		  const auth = data.split(',')
		  return auth
	  } else {
		  return Promise.reject(new Error(data))
	  }
  }
  const isDisableds = ref(false);
  const AdminProvinceId = ref('');
  const getDefaultProvice = async () => {
	  try {
		  let curAuth = await isAdmin()
	  let flag = curAuth.some(item=>item.includes('国家'))
	  isDisableds.value = !flag;
		  if (isDisableds.value) {
			  getLanderProvince().then(res => {
				  if (res.code == 200) {  
			AdminProvinceId.value = res.data
				  }else{
			AdminProvinceId.value = ''
		  }
			  })
			  getList();
		  } else {
			  getList()
		  }
	  } catch (error) {
  
	  }
  }
  getDefaultProvice()
  // getList();
  getProvinceData();
  getProvinceFormData();
  </script>
  <style scoped lang="scss">
	  .tab-title {
		  font-size: 16px;
		  font-weight: bold;
		  border-left: 4px solid var(--el-color-primary);
		  font-family: PingFangSC-Medium;
		  padding-left: 10px;
		  margin-bottom: 20px;
	  }
  </style>
  